package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import org.junit.Before;
import org.junit.Test;

import papers.Manuscript;
import papers.Review;
import users.Author;
import users.Reviewer;
import users.User;

import conference.Conference;

public class TestConference {

	/**
	 * The manuscript deadline.
	 */
	private Date my_manuscript_deadline;

	/**
	 * The review deadline.
	 */
	private Date my_review_deadline;

	/**
	 * The PC user.
	 */
	private User my_pc;
	
	/**
	 * The manuscript.
	 */
	private Manuscript my_manuscript;
	
	Conference my_conference;
	/**
	 * Initializes the Conference
	 */
	@Before
	public void setUp() {
		Author author_1 = new Author("george");
		my_pc = new Author("bob");
		my_manuscript_deadline = new Date();
		my_review_deadline = new Date();
		my_conference = new Conference(my_pc, "confA", my_manuscript_deadline,
				my_review_deadline, new ArrayList<User>());
		
		my_manuscript = new Manuscript(author_1,
				new Date(), "paperA", new File("A"));
		
		my_conference.submitManuscript(my_manuscript);
		
	}
	
	/**
	 * Tests adding a manuscript to the Conference class
	 * @throws IOException 
	 */
	@Test
	public void testSubmitManuscriptToConf() throws IOException {
		Author author_1 = new Author("george");
		Author author_2 = new Author("ABC");
		
		my_conference.addUser(author_1);
		my_conference.addUser(author_2);
		
		Manuscript test_manuscript2 = new Manuscript(author_2,
				new Date(), "paperB", new File("B"));
		
		assertEquals("Conf has no manuscripts", 1,
				my_conference.getManuscripts().size());

		assertEquals("The first manuscript is diff", my_conference.getManuscripts().get(0),
				my_manuscript);
		
		my_conference.submitManuscript(test_manuscript2);
		
		assertEquals("conf has one manuscript", 2,
				my_conference.getManuscripts().size());
		assertEquals("The second manuscript is diff", my_conference.getManuscripts().get(1),
				test_manuscript2);
	}

	/**
	 * Tests adding a Review to the Conference class
	 * @throws IOException 
	 */
	@Test
	public void testSubmitReviewToConf() throws IOException {
		Author author_1 = new Author("george");
		Author author_2 = new Author("ABC");
		
		my_conference.addUser(author_1);
		my_conference.addUser(author_2);
		
		Review test_review = new Review(new Reviewer("george"),
				new Date(), new File("A"));
		Manuscript test_manuscript = new Manuscript(author_1,
				new Date(), "paperA", new File("A"));
		
		Review test_review2 = new Review(new Reviewer("ABC"),
				new Date(), new File("B"));
		Manuscript test_manuscript2 = new Manuscript(author_2,
				new Date(), "paperB", new File("B"));
		
		assertEquals("Conf has no reviews", 0,
				my_conference.getReviews().size());
		
		my_conference.submitReview(test_review, test_manuscript);
		
		assertEquals("conf has one review", 1,
				my_conference.getReviews().size());
		assertEquals("The reiver is diff", my_conference.getReviews().get(0),
				test_review);
		
		my_conference.submitReview(test_review2, test_manuscript2);
		
		assertEquals("conf has one review", 2,
				my_conference.getReviews().size());
		assertEquals("The reiver is diff", my_conference.getReviews().get(1),
				test_review2);
		
	}
	
	/**
	 * tests conference info.
	 */
	@Test
	public void testConfInfo() {
		assertEquals("name is the same", "confA",
				my_conference.getConfName());
		
		assertEquals("manuscript deadline is diff.", my_manuscript_deadline,
				my_conference.getManuDate());
		
		assertEquals("review deadline is diff.", my_review_deadline,
				my_conference.getRevDate());
		
		assertEquals("PC is diff.", my_pc,
				my_conference.getPC());

	}
	
	/**
	 * tests setManuDate.
	 */
	@Test
	public void testsetManuDate() {
		Date date = new Date();
		my_conference.setManuDate(date);
		
		assertEquals("Date is not the same", my_conference.getManuDate(),
				date);
	}
	
	/**
	 * tests setRevDate.
	 */
	@Test
	public void testsetRevDate() {
		Date date = new Date();
		my_conference.setRevDate(date);
		
		assertEquals("Date is not the same", my_conference.getRevDate(),
				date);
	}
	
	/**
	 * tests getUsers.
	 * @throws IOException 
	 */
	@Test
	public void testgetUsers() throws IOException {
		assertEquals("User size is not one, should only has the PC"
				, my_conference.getUsers().size(), 1);
		
		Author author_1 = new Author("george");
		Author author_2 = new Author("ABC");
		
		my_conference.addUser(author_1);
		my_conference.addUser(author_2);
		
		assertEquals("User size is not three"
				, my_conference.getUsers().size(), 3);
		assertTrue("Author 1 is not in the user list"
				, my_conference.getUsers().contains(author_1));
		assertTrue("Author 2 is not in the user list"
				, my_conference.getUsers().contains(author_2));
	}
	
	/**
	 * tests Conference status.
	 */
	@Test
	public void testStatus(){
		assertFalse("Status is not false"
				, my_conference.getViewStatus());
		
		my_conference.setViewStatus(true);

		assertTrue("Status is not true"
				, my_conference.getViewStatus());
	}
	/**
	 * tests remove paper.
	 */
	@Test
	public void testRemove(){
		
		assertTrue("Conference doesnt not have the manuscript"
				, my_conference.getManuscripts().contains(my_manuscript));
		
		my_conference.delete(my_manuscript);

		assertFalse("Conference have the manuscript"
				, my_conference.getManuscripts().contains(my_manuscript));
	}	
	
}
